package Class_Object.多态的应用;

abstract public class Shape {

    abstract public void draw();
}
class Rect extends Shape {
    @Override
    public void draw() {
        System.out.println("矩形");
    }
}
class Triangle extends Shape{

    @Override
    public void draw() {
        System.out.println("三角形");
    }
}
class Cycle extends Shape {
    @Override
    public void draw() {

        System.out.println("圆形");
    }
}
class Test{
//    public static void drawMap(Shape shape) {
//        shape.draw();
//    }
    public static void main(String[] args) {
//        Shape shape = new Cycle();
//        Shape shape1 = new Triangle();
//        Shape shape2 = new Rect();
        Shape[] shapes = {new Cycle(),new Triangle(),new Rect()};
        for (Shape shape:shapes) {
            shape.draw();
        }
    }
    public static void main1(String[] args) {
        Cycle cycle = new Cycle();
        Rect rect = new Rect();
        Triangle triangle = new Triangle();
        String[] strings = {"cycle","rect","triangle"};
        for (String x:strings){
            if(x.equals("cycle")) {
                cycle.draw();
            } else if (x.equals("rect")) {
                rect.draw();
            } else if (x.equals("triangle")) {
                triangle.draw();
            }//但是if else的大量使用会造成圈复杂度太高
        }

    }
}



